<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>修改密码</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="../../../../layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="../../../../css/public.css">
	<link rel="stylesheet" href="use.css"  />
</head>
<body class="childrenBody">
<form class="layui-form layui-row changePwd" style="padding: 20px 20px 10px 20px;background-color: #fff;">
	<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
		<!-- <div class="layui-input-block layui-red pwdTips">旧密码请输入“123456”，新密码必须两次输入一致才能提交</div> -->
		<div class="layui-form-item">
			<label class="layui-form-label">旧密码</label>
			<div class="layui-input-block">
				<input type="password" value="" placeholder="请输入旧密码" lay-verify="required|oldPwd" class="layui-input pwd" id="oldPwd">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">新密码</label>
			<div class="layui-input-block">
				<input type="password" value="" placeholder="请输入新密码" lay-verify="required|newPwd"  class="layui-input pwd" id="newPwd">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">确认密码</label>
			<div class="layui-input-block">
				<input type="password" value="" placeholder="请确认密码" lay-verify="required|confirmPwd" class="layui-input pwd" id="confirmPwd">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit="" lay-filter="changePwd" onclick="dochange();return false;">立即修改</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</div>
</form>
<script type="text/javascript" src="../../../../layui/layui.js"></script>

<script>
	layui.use('layer', function () {
			layer = layui.layer;
			$ = layui.jquery;

			// 获取焦点
			$('#login-username').focus();

			// 直接回车登录
			$('input').keydown(function (e) {
				if (e.keyCode == 13) {
					dologin();
				}
			});
		});

		//登录
		function dochange() {
			var oldPwd = $.trim($('#oldPwd').val());
			var newPwd = $.trim($('#newPwd').val());
			var confirmPwd = $.trim($('#confirmPwd').val());
			var admin = localStorage.getItem("admin"); 
			var psw = localStorage.getItem("psw");
			if ( newPwd != confirmPwd) {
				layer.alert('新旧密码不一样请重新输入', { 'icon': 2 });
				console.log(newPwd)
				console.log(confirmPwd)
				return;
			}
			if (oldPwd != psw) {
				layer.alert('旧密码不正确请重新输入', { 'icon': 2 });
				return;
			}
			// $.post('http://127.0.0.1:8000/dologin',{'username':username,'password':password},function(res){
			// 	if(res.code>0){
			// 		layer.alert(res.msg,{'icon':2});
			// 	}else{
			// 		layer.msg(res.msg);
			// 		setTimeout(function(){location.href='./layui-admin/index'},1000);
			// 	}
			// },'json');
			 
			$.ajax({
				url: "http://127.0.0.1:8000/pswchange",
				type: "post",
				dataType: "JSON",
				data: { "username": admin, "password":newPwd },
				success: function (res) {
					if (res.code > 0) {
						layer.msg(res.msg);
					}
					if (res.code == 0) {
						layer.msg(res.msg);
					}
				}
			})

		}
</script>
</body>
</html>